package com.morn.weibo.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.morn.weibo.R;
import com.morn.weibo.WeiboApplication;
import com.morn.weibo.http.Fanfou;
import com.morn.weibo.types.User;

public class UserDetailFragment extends Fragment {

	private static final String TAG = "UserDetailFragment";

	private ImageView ivUserDetailPhoto;

	private Fanfou fanfou;

	private User user;

	private TextView tvUserDetail;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		fanfou = WeiboApplication.getFanfou();
		user = (User) getArguments().getSerializable("user");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.layout_user_detail,
				container, false);
		ivUserDetailPhoto = (ImageView) rootView
				.findViewById(R.id.ivUserDetailPhoto);
		tvUserDetail = (TextView) rootView.findViewById(R.id.tvUserDetail);
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		fanfou.downloadImage(user.getProfile_image_url_large(),
				ivUserDetailPhoto);
		tvUserDetail.setText(user.toString());
	}
}
